package com.myjob.controller;

import com.myjob.dto.UserDto;
import com.myjob.entity.BaseInfo;
import com.myjob.response.Result;
import com.myjob.service.BaseInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Chen Yuan
 * @create 2021-01-12  15:59
 */
@RestController
@Slf4j
@RequestMapping("/account")
public class BaseInfoController {
	@Autowired
	private BaseInfoService baseInfoService;

	/**
	 * 按照用户 Id 获取
	 * @param userId 用户编号
	 * @return
	 */
	@GetMapping("/baseInfo")
	public Result selectBaseInfoById(@RequestParam("userId") String userId){
		Result<BaseInfo> result = null;
		try {
			result = baseInfoService.selectBaseInfoById(userId);
		}catch (Exception e){
			e.printStackTrace();
		}
		return result;
	}

	/**
	 * 修改 基本信息 baseInfo
	 * @param baseInfo 基本信息
	 * @return
	 */
	@PostMapping("/baseInfo")
	public Result updateBaseInfoById(@RequestBody UserDto userDto){
		Result<BaseInfo> result = null;
		try {
			result = baseInfoService.updateBaseInfoById(userDto);
		}catch (Exception e){
			e.printStackTrace();
		}
		return result;
	}

	@PutMapping("/baseInfo")
	public Result insertBaseInfo(@RequestBody BaseInfo baseInfo){
		Result<BaseInfo> result = null;
		try {
			result = baseInfoService.insertBaseInfo(baseInfo);
		}catch (Exception e){
			e.printStackTrace();
		}
		return result;
	}
}
